package com.itheima.observer;

import java.util.ArrayList;

/**
 * @program: design
 * @description:
 * @author: zhanghz001
 * @create: 2020-11-26 15:33
 **/
public class Clock {
    //一对多,需要接受通知的对象
    ArrayList<AbstrackInfo> list = new ArrayList<>();

    public static void main(String[] args) {
        Clock clock = new Clock();
        clock.addInfo(new SleepInfo());
        clock.addInfo(new EatInfo());
        clock.update();

    }

    //通知
    private void update() {
        System.out.println("12点，通知大家吃饭，吃了睡觉！");
        for (AbstrackInfo abstrackInfo : list) {
            abstrackInfo.message();
        }
    }

    //需要添加通知的对象
    private void addInfo(AbstrackInfo abstrackInfo) {
        list.add(abstrackInfo);
    }

}
